import type { Slots } from 'vue';
import { isFunction } from '@sindresorhus/is';

export const getSlot = (slots: Slots, slotName = 'default', data?: Recordable) => {
  if (!slots || !Reflect.has(slots, slotName)) {
    return null;
  }

  if (!isFunction(slots[slotName])) {
    return null;
  }

  return slots[slotName]?.(data) || null;
};
